/**
 * Copyright &copy; 2012-2016 <a href="https://github.com/thinkgem/jeesite">JeeSite</a> All rights reserved.
 */
package com.thinkgem.jeesite.modules.menu.web;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;

import com.thinkgem.jeesite.common.config.Global;
import com.thinkgem.jeesite.common.persistence.Page;
import com.thinkgem.jeesite.common.web.BaseController;
import com.thinkgem.jeesite.common.utils.StringUtils;
import com.thinkgem.jeesite.modules.menu.entity.Goods3;
import com.thinkgem.jeesite.modules.menu.service.Goods3Service;

/**
 * 商品Controller
 * @author dby
 * @version 2020-07-12
 */
@Controller
@RequestMapping(value = "${adminPath}/menu/goods3")
public class Goods3Controller extends BaseController {

	@Autowired
	private Goods3Service goods3Service;

	@ModelAttribute
	public Goods3 get(@RequestParam(required=false) String id) {
		Goods3 entity = null;
		if (StringUtils.isNotBlank(id)){
			entity = goods3Service.get(id);
		}
		if (entity == null){
			entity = new Goods3();
		}
		return entity;
	}
	
	@RequiresPermissions("menu:goods3:view")
	@RequestMapping(value = {"list", ""})
	public String list(Goods3 goods3, HttpServletRequest request, HttpServletResponse response, Model model) {
		Page<Goods3> page = goods3Service.findPage(new Page<Goods3>(request, response), goods3); 
		model.addAttribute("page", page);
		return "modules/menu/goods3List";
	}

	@RequiresPermissions("menu:goods3:view")
	@RequestMapping(value = "form")
	public String form(Goods3 goods3, Model model) {
		model.addAttribute("goods3", goods3);
		return "modules/menu/goods3Form";
	}

	@RequiresPermissions("menu:goods3:edit")
	@RequestMapping(value = "save")
	public String save(Goods3 goods3, Model model, RedirectAttributes redirectAttributes) {
		if (!beanValidator(model, goods3)){
			return form(goods3, model);
		}
		goods3Service.save(goods3);
		addMessage(redirectAttributes, "保存商品成功");
		return "redirect:"+Global.getAdminPath()+"/menu/goods3/?repage";
	}
	
	@RequiresPermissions("menu:goods3:edit")
	@RequestMapping(value = "delete")
	public String delete(Goods3 goods3, RedirectAttributes redirectAttributes) {
		goods3Service.delete(goods3);
		addMessage(redirectAttributes, "删除商品成功");
		return "redirect:"+Global.getAdminPath()+"/menu/goods3/?repage";
	}



	@RequiresPermissions("menu:goods3:view")
	@RequestMapping(value = {"index"})
	public String list1(Goods3 goods3, HttpServletRequest request, HttpServletResponse response, Model model) {
		Page<Goods3> page = goods3Service.findPage(new Page<Goods3>(request, response), goods3);
		model.addAttribute("page", page);
		return "modules/menu/goods3Index";
	}


}